import 'package:quiver/time.dart';
import 'package:flutter/material.dart';
import 'dart:async';
class func{
  static String diffTime(DateTime a, DateTime b,) {
     String retString="";
    int diffTime=b.millisecondsSinceEpoch-a.millisecondsSinceEpoch;
    int minute=(diffTime/1000/60).floor();
    if(minute<60){
      return "${minute.toString()}分钟";
    }
     int hour=(minute/60).floor();
     if(hour<60){
       return "${hour.toString()}小时";
     }
     int day=(hour/24).floor();
     return  "${day.toString()}天";

  }

  static Future<Null>  confirm(BuildContext context,String content,Function callback) async {
    return showDialog<Null>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return new AlertDialog(
          title: new Text('提示'),
          content: new SingleChildScrollView(
            child: new ListBody(
              children: <Widget>[
                new Text(content),
              ],
            ),
          ),
          actions: <Widget>[
            new Container(
              child:  new FlatButton(
                child: new Text('确认'),
                onPressed: () {
                  callback(true);
                  Navigator.of(context).pop();
                },
              ),
              alignment: Alignment.centerLeft,
            ),
            new FlatButton(
              child: new Text('取消'),
              onPressed: () {
                callback(false);
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

  static Future<Null>  alertConfirm(BuildContext context,String content,Function callback) async {
    return showDialog<Null>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return new AlertDialog(
          title: new Text('提示'),
          content: new SingleChildScrollView(
            child: new ListBody(
              children: <Widget>[
                new Text(content),
              ],
            ),
          ),
          actions: <Widget>[
            new Container(
              child:  new FlatButton(
                child: new Text('确认'),
                onPressed: () {
                  Navigator.of(context).pop();
                  callback(true);

                },
              ),
              alignment: Alignment.centerLeft,
            ),
          ],
        );
      },
    );
  }
  static Future<Null>  alertInput(BuildContext context,String title,String input,Function callback) async {
    String text="";
    return showDialog<Null>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return new AlertDialog(
          title: new Text(title),
          content: new SingleChildScrollView(
            child: new ListBody(
              children: <Widget>[
                new TextField(
                  decoration: new InputDecoration(
                    hintText: input,
                  ),
                ),
              ],
            ),
          ),
          actions: <Widget>[
            new Container(
              child:  new RaisedButton(
                child: new Text('确认',style: new TextStyle( color: Colors.white,),),
                onPressed: () {
                  callback(true);
                  Navigator.of(context).pop();
                },
              ),
              alignment: Alignment.centerLeft,
            ),
            new RaisedButton(
              child: new Text('取消',style: new TextStyle( color: Colors.white,),),
              color: Colors.black12.withOpacity(0.5),
              onPressed: () {
                callback(false);
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }



  static MySnackBar(BuildContext context,String title,{Color color=Colors.white,Color bgColor=Colors.black,}){
    Scaffold.of(context).showSnackBar(
        new SnackBar(content: new Text(title,textAlign: TextAlign.center,style: new TextStyle(color:color ),),backgroundColor: bgColor.withOpacity(0.5),)
    );
  }

}